<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // 不设置过期时间，关闭后消失
        function setCookie(name,value,day=0) {
            // 过期时间不是必传
            if(day!=0) {
                // 业务 exprires
                var exprires = day*24*60*60*1000
                var date = new Date(+ new Date() + exprires)
                document.cookie = `${name}=${value};exprires${date.toUTCString()}`
                console.log(date.toUTCString())
            }else {
                document.cookie = `${name}=${escape(value)}`
            }
        }
        setCookie('name','age',1)
    </script>
</body>
</html>